<%--
  Created by IntelliJ IDEA.
  User: 风间琉璃
  Date: 2021/4/12
  Time: 9:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>水果查询页面</title>
</head>
<body>
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <script>
        $(document).ready(function () {
            $(".del").click(function () {
                var fruitId = $(this).attr("personId");
                //alert(fruitId);

                var delNode = $(this).parent().parent();
                $.ajax({
                    type:"post",
                    url:"FruitServlet?opr=del",
                    data:"fruitid="+fruitId,
                    dataType:"text",
                    success:function (data) {
                        if (data == "true"){
                            alert("删除成功！");
                            delNode.remove();
                        }else
                            alert("删除失败！");
                    }
                })
            });
        })
    </script>
    <c:if test="${empty list}">
        <script>
            location.href="FruitServlet";
        </script>
    </c:if>
    <form action="FruitServlet?opr=type" method="post">
        类型：<input type="text" name="type" placeholder="模糊查询">
        <input type="submit" value="提交">
    </form>
    <table border="1" style="text-align: center">
        <tr>
            <td>id</td>
            <td>类别</td>
            <td>品种</td>
            <td>产地</td>
            <td>总重量（公斤）</td>
            <td>单价（元/公斤）</td>
            <td>操作</td>
        </tr>
        <c:forEach var="fruit" items="${list}" varStatus="status">
            <tr <c:if test="${status.index % 2 eq 0}">style="background-color: #ED610C" </c:if>>
                <td>${fruit.fruitId}</td>
                <td>${fruit.type}</td>
                <td>${fruit.breed}</td>
                <td>${fruit.area}</td>
<%--                <td>${fruit.brief}</td>--%>
                <td>${fruit.weight}</td>
                <td>${fruit.price}</td>
                <td>
                    <a href="FruitServlet?opr=one&fruitid=${fruit.fruitId}">详情</a>
                    <a class="del" personId="${fruit.fruitId}" href="javascript:void(0)">删除</a>
                    <a href="FruitServlet?opr=upd&fruitid=${fruit.fruitId}">更新</a>
                </td>
            </tr>
        </c:forEach>
    </table>
    <c:if test="${pageIndex gt 1}"><a href="FruitServlet?opr=list&pageIndex=${pageIndex-1}">上一页</a></c:if>
    当前处于第${pageIndex}页，共${pageCount}页
    <c:if test="${pageIndex lt pageCount}"><a href="FruitServlet?opr=list&pageIndex=${pageIndex+1}">下一页</a></c:if>
    <button id="add">添加</button>
    <script>
        $("#add").click(function (){
            location.href="add.jsp";
        })
    </script>
</body>
</html>
